package com.kc.data.common.config;

import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author TP
 * @date 1/12/21 6:52 PM
 */
@Configuration
public class RocketMqProducerClientConfig {

    @Autowired
    private RocketMqConfig rocketMqConfig;

    @Bean(initMethod = "start", destroyMethod = "shutdown")
    public ProducerBean buildProducer() {
        //ProducerBean用于将Producer集成至Spring Bean中
        ProducerBean producer = new ProducerBean();
        //配置文件
        Properties properties = rocketMqConfig.getMqProperties();
        properties.setProperty(PropertyKeyConst.GROUP_ID, rocketMqConfig.getProducerGroupId());
        //设置发送超时时间，单位毫秒
        properties.setProperty(PropertyKeyConst.SendMsgTimeoutMillis, "4000");
        producer.setProperties(properties);
        return producer;
    }

}
